module.exports = function ($scope, $resource, $modal, toaster) {


	$scope.getSiteList = function (pageNo){
		var para = {
			'pageNo': pageNo,
            'pageSize': $scope.itemsPerPage,
            'status': $scope.searchform.status,
            'title': $scope.searchform.title
        }
        $resource('/api/as/tc/entitysite/entitySiteList', {}, {}).save(para, function(res){
			if (res.errcode === 0) {
				$scope.sitelist = res.data.results;
				$scope.totalItems = res.data.totalRecord;
			} else {
				toaster.error({title: '', body: res.errmsg});
			}
		});
    }
    
    init();
    //初始化列表
    function init(){
		$scope.currentPage = 1;
        $scope.itemsPerPage = 10;
        $scope.searchform = {};
		$scope.getSiteList(1);
    }

	$scope.editInfo = function (obj) {
		var modalInstance = $modal.open({
			template: require('../views/setSiteInfo.html'),
			controller: 'setSiteInfo',
			resolve: {
				siteInfo: function () {
					return obj;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function(result) {
			$scope.getSiteList($scope.currentPage);
		});
	}

	$scope.delete = function (obj) {
		if(confirm('确认删除此配送站点吗？')){
			$resource('/api/as/tc/entitysite/delete', {}, {}).save({'id':obj.id}, function(res){
				if(res.errcode === 0){
					toaster.success({title: '', body: '成功'});
					$scope.getSiteList($scope.currentPage);
				} else {
					toaster.error({title: '', body: '失败，请重试'});
				}
			});
		}
	}

};